package com.SweetWhite.UserManagement.model.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.SweetWhite.UserManagement.model.bean.Hero_User;
import com.SweetWhite.UserManagement.model.service.SelectService;
import com.SweetWhite.UserManagement.model.service.UpdateService;



@Controller
public class UpdateController extends HttpServlet{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Autowired
	private UpdateService service;
	@Autowired
	private SelectService s_service;
@RequestMapping("checkNo.action")
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// TODO Auto-generated method stub
int No=Integer.parseInt(req.getParameter("No"));
PrintWriter pw=resp.getWriter();
try {
	if(No==s_service.getHero_UserByNo(No).getNo()) {
		pw.print("排行存在，可以操作");
	}
} catch (Exception e) {
	// TODO: handle exception
	pw.print("哎呀，没有这个排行呢……");
}finally {
	pw.flush();
	pw.close();
}
}
@RequestMapping("update.action")
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// TODO Auto-generated method stub

PrintWriter pw=resp.getWriter();
Hero_User hu =new Hero_User();
hu.setNo(Integer.parseInt(req.getParameter("No")));
if(req.getParameter("No").isEmpty()==true) {
	pw.print("请输入排行");
}
hu.setNickName(req.getParameter("NickName"));
hu.setRealName(req.getParameter("RealName"));
hu.setSex(req.getParameter("Sex"));
hu.setShowTime(req.getParameter("ShowTime"));
hu.setPassword(req.getParameter("password"));
System.out.println(hu.toString());
service.updateHero_User(hu);
try {
	if (s_service.getHero_UserByNo(hu.getNo()).toString().isEmpty()==false){
		pw.print("修改成功");
	}
} catch (Exception e) {
	// TODO: handle exception
	pw.print("没有这个排行，改了个寂寞");
}finally {
	pw.flush();
	pw.close();
}
}
}

